/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package ep.m004.ui.uicontrollers;

import com.vaadin.data.util.BeanItem;
import com.vaadin.data.util.BeanItemContainer;
import ep.libs.implementations.AbstractModule;
import ep.persistence.entities.T005Patient;
import ep.persistence.entities.T006Prescription;
import ep.persistence.entities.T008Dosage;
import java.util.ArrayList;
import java.util.Collection;
import java.util.Iterator;

/**
 *
 * @author atsi
 */
public class M004Controller {

    private AbstractModule module;
    private T005Patient patient;

    public M004Controller(Object patientObject, AbstractModule module) {
        this.patient = (T005Patient) patientObject;
        this.module = module;
    }

    public T005Patient getPatient() {
        return patient;
    }

    public BeanItem<T005Patient> getPatientDataSource() {
        BeanItem<T005Patient> beanItem = new BeanItem<T005Patient>(patient);
        return beanItem;
    }

    public BeanItemContainer<T008Dosage> getDosageDataSource() {
        Collection<T008Dosage> dosages = new ArrayList<T008Dosage>();
        patient.getT006PrescriptionCollection();
        for (Iterator<T006Prescription> it = patient.getT006PrescriptionCollection().iterator(); it.hasNext();) {
            T006Prescription t006Prescription = it.next();
            for (Iterator<T008Dosage> it1 = t006Prescription.getT008DosageCollection().iterator(); it1.hasNext();) {
                T008Dosage t008Dosage = it1.next();
                if (t008Dosage.getPrescribed() != null && t008Dosage.getPrescribed()) {
                    dosages.add(t008Dosage);
                }
            }
        }
        return new BeanItemContainer<T008Dosage>(T008Dosage.class, dosages);
    }
}
